/**
 * 时间转换工具类
 */
export class timeUtils {
	/**
	 * 将秒数转换为年、天、小时、分钟、秒的对象
	 * @param seconds 秒数
	 * @returns 包含转换后时间的对象
	 */
	static secondsToTimeObject(seconds: number) {
		const SECONDS_IN_YEAR = 365 * 24 * 60 * 60
		const SECONDS_IN_DAY = 24 * 60 * 60
		const SECONDS_IN_HOUR = 60 * 60
		const SECONDS_IN_MINUTE = 60

		const years = Math.floor(seconds / SECONDS_IN_YEAR)
		seconds = seconds % SECONDS_IN_YEAR

		const days = Math.floor(seconds / SECONDS_IN_DAY)
		seconds = seconds % SECONDS_IN_DAY

		const hours = Math.floor(seconds / SECONDS_IN_HOUR)
		seconds = seconds % SECONDS_IN_HOUR

		const minutes = Math.floor(seconds / SECONDS_IN_MINUTE)
		const remainingSeconds = seconds % SECONDS_IN_MINUTE

		return {
			years,
			days,
			hours,
			minutes,
			seconds: remainingSeconds
		}
	}

	/**
	 * 将秒数转换为可读的时间字符串
	 * @param seconds 秒数
	 * @param showZeroValues 是否显示值为0的单位，默认为false
	 * @returns 格式化后的时间字符串
	 */
	static formatTimeString(seconds: number, showZeroValues: boolean = false): string {
		const time = this.secondsToTimeObject(seconds) // 修复：移除多余空格
		const parts: string[] = []

		if (time.years > 0 || showZeroValues) {
			parts.push(`${time.years}年`)
		}
		if (time.days > 0 || showZeroValues) {
			parts.push(`${time.days}天`)
		}
		if (time.hours > 0 || showZeroValues) {
			parts.push(`${time.hours}小时`)
		}
		if (time.minutes > 0 || showZeroValues) {
			parts.push(`${time.minutes}分钟`)
		}
		if (time.seconds > 0 || showZeroValues) {
			parts.push(`${time.seconds}秒`)
		}

		return parts.length > 0 ? parts.join('') : '0秒'
	}
}
